// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-17

#include "stdafx.h"
#include "db_sourceset.h"
#include "db_session.h"
#include "db_command.h"
#include "db_utility.h"
#include "svr_server.h"
#include "svr_showinfo.h"

namespace JoyServer
{

// class CJoyDbSourceSet

CJoyDbSourceSet::CJoyDbSourceSet(void)
{
}

CJoyDbSourceSet::~CJoyDbSourceSet(void)
{
}

bool CJoyDbSourceSet::Create(CJoyServer* pServer, CJoyDbSession& servSess, int nDBType)
{
    HRESULT hr;

    // create and open command
    CJoyDbCommand rsSources;
    if(!JoyInvokeCommand(pServer, servSess, rsSources, 
        L"select_db_server_by_type", nDBType))
    {
        return false;
    }

    // read dbserver settings.
    while(HasMoreRow(hr = rsSources.MoveNext()))
    {
        CJoyDbSource s;
        if(!LoadDbSource(pServer, s, rsSources))
        {
            return false;
        }
        m_sources.Add(s);
    }

    if(m_sources.GetCount() == 0)
    {
        pServer->m_showInfo->QueueTimeColorText(InfoColor_Error,
            "failed to read from server database while creating source set.\n");
        return false;
    }

    return true;
}

void CJoyDbSourceSet::Destroy()
{
    m_sources.RemoveAll();
}

// class CJoyOServDbSourceSet

CJoyOServDbSourceSet::CJoyOServDbSourceSet()
{
}

CJoyOServDbSourceSet::~CJoyOServDbSourceSet()
{
}

bool CJoyOServDbSourceSet::Create(CJoyServer* pServer, CJoyDbSession& servSess)
{
    pServer->m_showInfo->QueueTimeText("load online server db settings...\n");
    return __super::Create(pServer, servSess, DBServer_OnlineServer);
}

// class CJoyOUserDbSourceSet

CJoyOUserDbSourceSet::CJoyOUserDbSourceSet()
{
}

CJoyOUserDbSourceSet::~CJoyOUserDbSourceSet()
{
}

bool CJoyOUserDbSourceSet::Create(CJoyServer* pServer, CJoyDbSession& servSess)
{
    pServer->m_showInfo->QueueTimeText("load online user db settings...\n");
    return __super::Create(pServer, servSess, DBServer_OnlineUser);
}

} // namespace JoyServer